# @Version        : 1.0
# @Update Time    : 2025/3/15 14:50
# @File           : registration_view.py
# @IDE            : PyCharm
# @Desc           : 文件描述信息
import flet as ft


class RegistrationView(ft.Container):
    def __init__(self, page: ft.Page, params: dict = None):
        super().__init__()
        self.page = page
        self.params = params
        self.primary_color = "#4CAF50"  # 主绿色
        self.input_border = "#BDBDBD"  # 输入框边框色

        # 构建界面元素
        self.name_field = self._build_input_field("姓名", "", ft.icons.PERSON_OUTLINE)
        self.email_field = self._build_input_field("邮箱地址", "", ft.icons.EMAIL_OUTLINED)
        self.password_field = self._build_password_field()

        # 主容器配置
        self.width = 400
        self.padding = 30
        self.border_radius = 10

        self.content = ft.Column(
            controls=[
                self._build_header(),
                self.name_field,
                self.email_field,
                self.password_field,
                self._build_forgot_password(),
                self._build_register_button(),
                self._build_divider(),
                self._build_social_login(),
                self._build_login_prompt()
            ],
            spacing=20,
            horizontal_alignment=ft.CrossAxisAlignment.CENTER
        )

    def _build_header(self):
        return ft.Text("欢迎回到生鲜到家！", size=28, weight=ft.FontWeight.BOLD, color=self.primary_color)

    def _build_input_field(self, label, hint_text, icon):
        return ft.TextField(
            label=label,
            value=hint_text,
            prefix_icon=icon,
            border_color=self.input_border,
            focused_border_color=self.primary_color,
            border_radius=8,
            height=50,
            text_size=14,
            content_padding=15,
            label_style=ft.TextStyle(color="#666666")
        )

    def _build_password_field(self):
        return ft.TextField(
            label="密码",
            password=True,
            can_reveal_password=True,
            prefix_icon=ft.icons.LOCK_OUTLINE,
            border_color=self.input_border,
            focused_border_color=self.primary_color,
            border_radius=8,
            height=50,
            text_size=14,
            content_padding=15,
            label_style=ft.TextStyle(color="#666666")
        )

    def _build_forgot_password(self):
        return ft.TextButton(
            content=ft.Text(
                "忘记密码?",
                color=self.primary_color,
                size=12
            ),
            on_click=lambda e: print("忘记密码")
        )

    def _build_register_button(self):
        return ft.ElevatedButton(
            content=ft.Text(
                "注册",
                size=16,
                weight=ft.FontWeight.W_500
            ),
            bgcolor=self.primary_color,
            color=ft.colors.WHITE,
            width=300,
            height=45,
            elevation=0,
            on_click=lambda e: self.on_register(),
            style=ft.ButtonStyle(
                shape=ft.RoundedRectangleBorder(radius=8)
            )
        )

    def _build_divider(self):
        return ft.Row(
            controls=[
                ft.Divider(color="#BDBDBD"),
                ft.Text("或者使用", size=12, color="#666666"),
                ft.Divider(color="#BDBDBD")
            ],
            alignment=ft.MainAxisAlignment.CENTER,
            spacing=10,
            width=300
        )

    def _build_social_login(self):
        return ft.Row(
            [
                # ft.Row(
                #     controls=[
                #         ft.Container(expand=True, height=1, bgcolor="#BDBDBD"),
                #         ft.Text("或者使用", color="#333333", size=12),
                #         ft.Container(expand=True, height=1, bgcolor="#BDBDBD")
                #     ],
                #     alignment=ft.MainAxisAlignment.CENTER,
                #     spacing=10
                # ),
                ft.IconButton(
                    icon=ft.icons.WECHAT,
                    icon_color="#09B83E",
                    icon_size=30,
                    tooltip="微信登录"
                ),
                ft.IconButton(
                    icon=ft.icons.PAYMENT,
                    icon_color="#00A1E9",
                    icon_size=30,
                    tooltip="支付宝登录"
                ),
                ft.IconButton(
                    ft.icons.TIKTOK,
                    icon_color="#00A1E9",
                    icon_size=30,
                    tooltip="抖音"
                )
            ], spacing=30, alignment=ft.MainAxisAlignment.CENTER
        )

    def _build_login_prompt(self):
        return ft.Row(
            [
                ft.Text("已经有账户？", size=12, color="#666666"),
                ft.TextButton(
                    content=ft.Text(
                        "登录",
                        color=self.primary_color,
                        size=12
                    ),
                    on_click=lambda e: self.on_login()
                )
            ], spacing=5, alignment=ft.MainAxisAlignment.CENTER
        )

    # 登录逻辑
    def on_login(self):
        print("跳转到登录页面")

    # 注册逻辑
    def on_register(self):
        data = {
            "name": self.name_field.value,
            "email": self.email_field.value,
            "password": self.password_field.value
        }
        print(f"注册信息：{data}")
